package spil;

import desktop_resources.GUI;

public class Fleet extends Ownable {
	private static final int[] RENT = {75, 150, 300, 600};
	
	public Fleet(int price, int fieldNumber) {
		super(price, fieldNumber);
	}
	
	public void landOnField(Player p) {
		if(owner == null) {
			boolean buy = GUI.getUserLeftButtonPressed(title + " er ikke ejet", "køb", "ignorer");
			if(buy) {
				if(p.getBalance() > price)
						p.addFleet();
				buy(p);
			}
			else GUI.getUserButtonPressed(p + " købte ikke " + title, "ok");
		}
		else {
			if(p.getAccount().getBalance() < getRent()) {
				GUI.getUserButtonPressed(p + " betaler " + p.getBalance() + "\n til " + owner, "ok");
				owner.getAccount().insert(p.getBalance());
				p.getAccount().withdraw(p.getBalance());
			}
			else if(p!=owner) {
				GUI.getUserButtonPressed(p + " betaler " + getRent() + "\n til " + owner, "ok");
				p.getAccount().withdraw(getRent());
				owner.getAccount().insert(getRent());
			}
			else GUI.getUserButtonPressed(owner + " ejer " + title, "ok");
		}
	}
	
	public int getRent() {
		return RENT[owner.getFleets() - 1];
	}
}
